[contents] [prev] [next] [top] [bottom] (6 out of 17)

Names

There are two kinds of names in ScriptX, lexical names and name literals. Lexical names are used to name variables and other denotable things, including functions and local function arguments. Name literals can be used as labels for function arguments, as keys in keyed collections, or anywhere else that a simple label might be required.

ScriptX names are case insensitive. That is, upper and lower case letters are treated the same. However, ScriptX remembers the case used the first time a new name appears and uses that case whenever it displays that name.

Throughout the Kaleida Technical Reference Series, the following case conventions are used:

		appendNew
beginDecompressSeq

		SequencePlayer
KeyedLinkedList

ScriptX defines about a hundred reserved words that cannot be used as lexical names. (They can be used to name keyword arguments for functions.) For a complete list of reserved words, see Table A-3 on page 232.

The ScriptX core classes define the names of many classes, variables, methods, keywords, global functions, global variables, and global constants. These names are imported into any module that uses the ScriptX module. A script can override these names, both globally and locally. It is quite common to override them locally. For example, a class may use the name of another class internally as the name of an instance variable, often an instance variable that it uses to store an embedded object. Although it is permitted, it is not good programming practice to override any of these names globally.

Lexical Names

Lexical names are used to name things in a program that the compiler must interpret during compilation, such as variables, local functions, and function arguments.

Names must begin with an alphabetic character or an underscore ( _ ). They can contain only uppercase and lowercase letters (A-Z, a-z), numbers, or the underscore character. Names cannot contain spaces, tabs, special characters, or non-alphanumeric characters such as symbols and punctuation. They can be up to 256 characters in length.

Here are some examples of valid names:

foo
mylist
_x
HugePulsingCreatureFromTheCratersOfVenus 
bignum4500
oswald_acted_alone

Here are some examples of names that are invalid:

23skidoo -- invalid, because it starts with a number
curses@(*&#!*@& -- invalid, because it contains symbols
spread out -- interpreted as two names, because it contains a space
aïda -- contains an accented or inflected character

Name Literals

Unlike lexical names, which are used to name things at compile time, name literals denote NameClass instances which exist at run time. Name literals evaluate to NameClass objects.

	@foo

	intern NameClass ("foo" + "bar")

Name literals follow the same upper and lower case conventions as lexical names. Here are some more examples and uses of name literals:

@utterly_undefined_thing
prin variableThing @normal debug -- used as a label for an argument
animals := #(@snake:"cobra", @bird:"sparrow", @fish:"guppy")

Name literals form a proper set. Multiple occurrences of a name literal with the same sequence of characters always evaluate to the same object. For example, the names @lefthanded, @LeftHanded, and @LEFTHANDED are not merely equal-they represent the same object. Name literals can be stored and compared more efficiently than strings, since multiple instances of strings may contain the same sequence of characters but are still different objects.

Name literals are useful as labels to make your scripts more readable. For example, if a function has an argument that is always one of three values, you can use name literals for those values instead of using numbers or strings. Additionally, name literals can be used as keys in key-value pairs, or anywhere else you need a valueless label in a script. Name literals are used extensively in this way by the ScriptX core classes.


This document is part of the ScriptX Language Guide, one of the volumes of the ScriptX Technical Reference Series. ScriptX is developed by the ScriptX Engineering Team at Apple Computer, successor to the Kaleida Engineering Team at Kaleida Labs, Inc.

Copyright 1996 Apple Computer, Inc. All Rights Reserved.